import socketserver模块
import os
import hashlib


def get_md5(code, randseq):
    md5 = hashlib.md5(code)
    md5.update(randseq)
    res = md5.hexdigest()
    return res

code = b'jackbigdick' #本地密码
sk = socketserver模块.socket()
sk.bind(('127.0.0.1', 9000))

sk.listen()

conn, addr = sk.accept()
randseq = os.urandom(32)
conn.send(randseq)
res = get_md5(code, randseq)
ret = conn.recv(32).decode('utf-8')
print(ret)
if ret == res:
    print('合法')
else:
    print('非法')

conn.close()
sk.close()